package observer.example;

import java.util.ArrayList;
import java.util.List;

/**
 * 秘书通知者
 * @author Chen Guang
 * @date 2019/4/9 0009 下午 16:13
 */
public class SecretarySubject implements Subject {

    private List<Observer> observers = new ArrayList<>();
    private String subjectState;

    @Override
    public void attach(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObserver() {
        for (Observer observer : observers) {
            observer.update();
        }
    }

    @Override
    public String getSubjectState() {
        return subjectState;
    }

    @Override
    public void setSubjectState(String str) {
        this.subjectState = str;
    }
}
